- 
                Notifications
    You must be signed in to change notification settings 
- Fork 711
feat: implement Interface for MCPServer and update server references #424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the  You can disable this status message by setting the  """ WalkthroughThis change introduces a new  Changes
 Possibly related PRs
 Suggested labels
 Suggested reviewers
 Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit: 
 SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
 Other keywords and placeholders
 CodeRabbit Configuration File ( | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
- examples/custom_server/main.go(1 hunks)
- server/server_interface.go(1 hunks)
- server/sse.go(3 hunks)
- server/stdio.go(2 hunks)
- server/streamable_http.go(2 hunks)
🔇 Additional comments (5)
server/stdio.go (1)
28-28: LGTM! Clean interface abstraction.The change from concrete
*MCPServertoInterfacetype properly implements dependency inversion, enabling extensibility while maintaining backward compatibility.Also applies to: 115-115
server/streamable_http.go (1)
120-120: LGTM! Consistent interface adoption.The changes align with the interface abstraction pattern applied across all server implementations.
Also applies to: 135-135
server/sse.go (1)
121-121: LGTM! Complete interface migration including test utilities.The interface abstraction is consistently applied to both the main constructor and test helper, ensuring uniformity across the codebase.
Also applies to: 261-261, 280-280
server/server_interface.go (1)
1-54: Excellent interface design with comprehensive documentation.The
Interfaceabstraction is well-structured with:
- Clear method signatures covering all essential server operations
- Thorough documentation for each method
- Proper compile-time validation that
MCPServerimplements the interface- Good separation of concerns enabling custom implementations
This follows interface segregation and dependency inversion principles effectively.
examples/custom_server/main.go (1)
1-257: Excellent example implementation demonstrating interface extensibility.This custom server implementation effectively showcases:
- Clean wrapper pattern for adding cross-cutting concerns
- Comprehensive structured logging using slog
- Proper delegation to the wrapped server
- Production-ready server lifecycle management with graceful shutdown
This serves as a great reference for developers wanting to extend MCP server functionality.
5533d56    to
    d630605      
    Compare
  
    There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
examples/custom_server/main.go (1)
31-64: Handle JSON unmarshaling error for better robustness.The logging implementation is comprehensive, but the JSON unmarshaling on line 37 should handle potential errors for better robustness.
Apply this diff to handle the unmarshaling error:
- json.Unmarshal(message, &baseMsg) + if err := json.Unmarshal(message, &baseMsg); err != nil { + l.logger.WarnContext(ctx, "failed to parse message for logging", slog.String("error", err.Error())) + }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
- examples/custom_server/main.go(1 hunks)
- server/server_interface.go(1 hunks)
- server/sse.go(3 hunks)
- server/stdio.go(2 hunks)
- server/streamable_http.go(2 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
- server/sse.go
- server/streamable_http.go
- server/stdio.go
- server/server_interface.go
🔇 Additional comments (3)
examples/custom_server/main.go (3)
17-29: LGTM! Clean wrapper implementation.The
LoggingMCPServerstruct properly demonstrates how to use the newserver.Interfaceabstraction to create custom server implementations. The constructor follows standard Go patterns.
66-180: Excellent interface implementation with comprehensive logging.All interface methods are properly implemented with consistent logging patterns, good error handling, and appropriate delegation to the underlying server. This provides excellent observability for MCP server operations.
182-257: Well-structured server setup and lifecycle management.The main function demonstrates proper MCP server configuration with structured logging, example tools/resources, and graceful shutdown handling. The implementation correctly uses the new
server.Interfaceabstraction and provides a good example for developers.Note: The outdated comment mentioned in past reviews appears to have been already addressed.
| Thanks for the PR. IMHO, this would be helpful to have. | 
Description
Introduce
Interfacefor server extensibility to decouple server implementations from the concreteMCPServertype, enabling custom server implementations while maintaining full backward compatibility.This allows developers to implement custom server behavior (logging, metrics, rate limiting, etc.) by wrapping the core server functionality through a well-defined interface contract.
Type of Change
Checklist
Additional Information
Problem
All transports (
SSEServer,StdioServer,StreamableHTTPServer) are tightly coupled to*MCPServer, preventing custom server implementations for logging, metrics, rate limiting, etc.Solution
Add
Interfacedefining the complete server contract: